<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="auto" v-show="showSearch">
            <el-form-item label="id">
                <el-input
                    v-model="queryParams.id"
                    placeholder="请输入id"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="用户ID">
                <el-input
                    v-model="queryParams.userid"
                    placeholder="请输入用户ID"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="退款订单号">
                <el-input
                    v-model="queryParams.order_sn"
                    placeholder="请输入退款订单号"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="手机号">
                <el-input
                    v-model="queryParams.phone"
                    placeholder="请输入手机号"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="用户类型">
                <el-input
                    v-model="queryParams.user_type"
                    placeholder="请输入用户类型"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="昵称">
                <el-input
                    v-model="queryParams.niick_name"
                    placeholder="请输入昵称"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="退款状态">
                <el-select v-model="queryParams.refund_status"
                           clearable
                           placeholder="请选择">
                    <el-option
                        v-for="item in refundStatusOptions"
                        :key="item.value"
                        :label="item.label"
                        :value="parseInt(item.value)"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="支付类型">
                <el-select v-model="queryParams.pay_type"
                           clearable
                           placeholder="请选择">
                    <el-option
                        v-for="item in payTypeOptions"
                        :key="item.value"
                        :label="item.label"
                        :value="parseInt(item.value)"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="&nbsp;">
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button
                    type="warning"
                    plain
                    icon="Download"
                    @click="handleExport"
                >导出
                </el-button>
            </el-col>
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="list">
            <el-table-column label="ID" align="center" prop="id"/>
            <el-table-column label="用户ID" align="center" prop="userid" />
            <el-table-column label="退款订单号" align="center" prop="order_sn" />
<!--            <el-table-column label="充值订单号" align="center" prop="order_sn" />-->
            <el-table-column label="申请退款金额" align="center" prop="need_price" :formatter="(row) => {return '￥' + row.need_price}"/>
            <el-table-column label="已退款金额" align="center" prop="already_price" :formatter="(row) => {return '￥' + row.already_price}"/>
            <el-table-column label="未退款金额" align="center" prop="not_price" :formatter="(row) => {return '￥' + row.not_price}"/>
            <el-table-column label="创建时间" align="center" prop="create_time" width="180">
                <template slot-scope="{row}">
                    <span>{{ parseTime(row.create_time) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="退款时间" align="center" prop="create_time" width="180">
                <template slot-scope="{row}">
                    <span>{{ parseTime(row.refund_time) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="支付状态" align="center" prop="pay_status">
                <template slot-scope="{row}">
                    <dict-tag :options="refundStatusOptions" :value="row.refund_status" />
                </template>
            </el-table-column>
            <el-table-column label="支付类型" align="center" prop="pay_type">
                <template slot-scope="{row}">
                    <dict-tag :options="payTypeOptions" :value="row.pay_type" />
                </template>
            </el-table-column>
            <el-table-column label="手机号" align="center" prop="phone" :show-overflow-tooltip="true"/>
            <el-table-column label="所属运营商" align="center" prop="OperatorName" :show-overflow-tooltip="true"/>
            <el-table-column label="用户类型" align="center" prop="user_type" :show-overflow-tooltip="true"/>
            <el-table-column label="昵称" align="center">
                <template slot-scope="{row}">
                    {{row.niick_name}}
                </template>
            </el-table-column>
            <el-table-column label="头像地址" align="center">
                <template slot-scope="{row}">
                  <el-image
                    v-if="row.avatar"
                    style="width: 40px; height: 40px"
                    :src="row.avatar"
                    :preview-src-list="[row.avatar]">
                  </el-image>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="{row}">
                    <el-button link
                       type="primary"
                       @click="handleUpdate(row, 1)"
                       v-if="scope.row.refund_status == '0'">确定退款
                    </el-button>
                    <el-button link
                       type="danger"
                       @click="handleUpdate(row, -1)"
                       v-if="scope.row.refund_status == '0'">驳回提现
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
        <el-dialog title="退款详情" :visible.sync="refundDetailDialogVisible" width="60%" append-to-body>
            <RefundDetail :recharge_id="curr_id" />
        </el-dialog>
        <el-dialog title="扣费详情" :visible.sync="deductionDetailDialogVisible" width="60%" append-to-body>
            <RefundDetail :recharge_id="curr_id" />
        </el-dialog>
    </div>


</template>

<script>
import * as api from "@/api/finance/refund";
import RefundDetail from "@/components/Common/user/components/RefundDetail.vue";
export default {
  name: 'RechargeRecord',
  components: {  },
  props: {
    uid: {
      type: Number,
      required: true
    },
  },
  data() {
    return {
      list:[],
      loading:true,
      showSearch:false,
      total:0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      form: {},
      rules: {},
      refundStatusOptions:[
        { label: '待退款', value: '0' },
        { label: '退款成功', value: '1' },
        { label: '已取消', value: '-1' },
      ],
      payTypeOptions: [
          { label: '微信支付', value: '1' },
          { label: '支付宝支付', value: '2' },
          // { label: '后台充值', value: '3' },
      ],
      curr_id:0,
      refundDetailDialogVisible:false,
      deductionDetailDialogVisible:false,
    };
  },
  mounted(){
    this.queryParams.userid = this.uid
    this.getList()
  },
  methods: {
    getList() {/** 查询列表 */
      this.loading = true;
      api.listRefund(this.queryParams).then(response => {
          this.list = response.rows || [];
          this.total = response.total || 0;
          this.loading = false;
      });
    },
    handleQuery() {/** 搜索按钮操作 */
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {/** 重置按钮操作 */
      this.dateRange = [];
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
      };
      this.resetForm("queryRef");
      this.handleQuery();
    },
    handleExport() {/** 导出按钮操作 */
      this.download(api.EXPORT_URL, {
          ...this.queryParams.value
      }, `recharge_${new Date().getTime()}.xlsx`);
    },
    handleUpdate(row, refund_status) {
      var tips;
      if (refund_status == 1) {
          tips = '确定退款？';
      } else if (refund_status == -1) {
          tips = '驳回提现？';
      }
      this.$modal.confirm(tips).then( ()=> {
          return api.updateRefund({id: row.id, refund_status: refund_status});
      }).then(() => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
      }).catch(() => {
      });
    },
  }
}
</script>
